﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using TjZheng.Mvc;
using TjZheng.Framework;
using TjZheng.Power.DataEntity;

namespace TjZheng.CMS.Process
{
    public abstract class CMSWebViewPage<TModel> : TjZhengWebViewPage<TModel>
    {
        /// <summary>
        /// 跟踪参数1
        /// </summary>
        protected string TransferID
        {
            get
            {
                return HttpContext.Current.GetItems("TransferID") as string;
            }
            set
            {
                HttpContext.Current.SetItems("TransferID", value);
            }
        }
        /// <summary>
        /// 跟踪参数2
        /// </summary>
        protected string TransferTwoID
        {
            get
            {
                return HttpContext.Current.GetItems("TransferTwoID") as string;
            }
            set
            {
                HttpContext.Current.SetItems("TransferTwoID", value);
            }
        }
        /// <summary>
        /// 跟踪参数3
        /// </summary>
        protected string TransferThreeID
        {
            get
            {
                return HttpContext.Current.GetItems("TransferThreeID") as string;
            }
            set
            {
                HttpContext.Current.SetItems("TransferThreeID", value);
            }
        }
        /// <summary>
        /// 跟踪参数4
        /// </summary>
        protected string TransferFourID
        {
            get
            {
                return HttpContext.Current.GetItems("TransferFourID") as string;
            }
            set
            {
                HttpContext.Current.SetItems("TransferFourID", value);
            }
        }
        /// <summary>
        /// 当前用户
        /// </summary>
        public UserInfo CurrentUser
        {
            get
            {
                return HttpContext.Current.GetItems("CurrentUser") as UserInfo;
            }
        }
        /// <summary>
        /// 当前用户角色
        /// </summary>
        public List<GroupInfo> CurrentRoles
        {
            get
            {
                return HttpContext.Current.GetItems("CurrentRoles") as List<GroupInfo>;
            }
        }
        /// <summary>
        /// 当前按钮工具栏
        /// </summary>
        protected ButtonTool CurrentButtonTool
        {
            get
            {
                var objButtonTool = HttpContext.Current.GetItems("ButtonTool") as ButtonTool;
                if (objButtonTool == null)
                {
                    objButtonTool = new ButtonTool();
                    HttpContext.Current.SetItems("ButtonTool", objButtonTool);
                }
                return objButtonTool;
            }
            set
            {
                HttpContext.Current.SetItems("ButtonTool", value);
            }
        }
        /// <summary>
        /// 是否检查用户权限
        /// </summary>
        protected bool IsCheckUserPower
        {
            get
            {
                return ConfigHelper.GetBoolValue("IsCheckUserPower", true);
            }
        }
        /// <summary>
        /// 是否 从Redis检查用户权限
        /// </summary>
        protected bool IsCheckUserPowerRedis
        {
            get
            {
                return ConfigHelper.GetBoolValue("IsCheckUserPowerRedis", true);
            }
        }
        /// <summary>
        /// 输出跟踪参数
        /// </summary>
        /// <returns></returns>
        protected virtual string OutPutTransfers()
        {
            List<string> objTransfers = new List<string>();
            if (TransferID.IsNoNull())
            {
                objTransfers.Add(string.Format("TransferID={0}", TransferID));
            }
            if (TransferTwoID.IsNoNull())
            {
                objTransfers.Add(string.Format("TransferTwoID={0}", TransferTwoID));
            }
            if (TransferThreeID.IsNoNull())
            {
                objTransfers.Add(string.Format("TransferThreeID={0}", TransferThreeID));
            }
            if (TransferFourID.IsNoNull())
            {
                objTransfers.Add(string.Format("TransferFourID={0}", TransferFourID));
            }
            return objTransfers.JoinString("&");
        }
    }
}
